#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>

int main()
{
	struct stat buf;
	int st = stat("a.txt",&buf);
	if(st == -1) perror("stat") , exit(-1);
	printf("buf.st_size = %d\n",buf.st_size);
	printf("buf.st_mode = %o\n",buf.st_mode);
	printf("buf.st_mtime = %s",ctime(&buf.st_mtime));
	printf("buf.st_nlink = %d\n",buf.st_nlink);
	printf("buf.st_uid = %d\n",buf.st_uid);
	printf("buf.st_gid = %d\n",buf.st_gid);
	
	printf("权限:%o\n",buf.st_mode & 07777);
	/*
	if((buf.st_mode & S_IFREG) == S_IFREG)
		printf("This is a regular file\n");
	if((buf.st_mode & S_IFDIR) == S_IFDIR)
		printf("This is a directory\n");*/
		
	if(S_ISREG(buf.st_mode))
		printf("This is a regular file\n");
	if(S_ISDIR(buf.st_mode))
		printf("This is a directory\n");
}
